<template>
  <div>
    <el-row style="margin-bottom: 40px">
      <el-col :span="6">
        <el-card style="color: #409EFF">
          <div>用户总数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">100人</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #F56C6C">
          <div>销售额</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">$100</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #67C23A">
          <div>在线人数</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">100人</div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card style="color: #E6A23C">
          <div>销售冠军</div>
          <div style="padding: 10px 0;text-align: center;font-weight: bold">喜羊羊</div>
        </el-card>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="13">
        <div id="main" style="width: 600px;height: 500px"></div>
      </el-col>
      <el-col :span="11">
        <div id="pie" style="width: 600px;height: 500px"></div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts';
import request from "@/utils/request";
export default {
  name: "Home",
  data() {
    return {

    }
  },
  mounted() {
    //页面渲染后再触发
    //折线图
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option;

    option = {
      title: {
        text: '近七日订单数',
        subtext: '数据详情',
        left: 'center'
      },
      xAxis: {
        type: 'category',
        data: ['一','二','三','四','五','六','日']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line'
        },
        {
          data: [],
          type: 'bar'
        }
      ]
    };
    request.get("order/eChart/getLineBySales").then(res => {
      option.series[0].data = res.data;
      option.series[1].data = res.data;
      myChart.setOption(option);
    })

    //饼状图
    var pieDom = document.getElementById('pie');
    var pieChart = echarts.init(pieDom);
    var pieOption;

    pieOption = {
      title: {
        text: '销量最高的三个菜品',
        subtext: '比例数',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: '50%',
          data: [
            { value: 1048, name: '胡萝卜炒肉' },
            { value: 735, name: '西红柿炒蛋' },
            { value: 580, name: '牛排' },
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };
    request.get("order/eChart/getPie").then(res => {
      pieOption.series[0].data = [
        { value: res.data[0].sale, name: res.data[0].name },
        { value: res.data[1].sale, name: res.data[1].name },
        { value: res.data[2].sale, name: res.data[2].name },
      ]
      pieChart.setOption(pieOption);
    })
  }
}
</script>

<style scoped>

</style>